<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@include file="../common/jspcommon.jsp" %>
<script type="text/javascript">
$(function(){
		$("#doing_submit").click(function(){
			if(${superMan.identifier=='superMan'}){
				GUOGUO.superUser();
			}else{
				faBiao();
			}
			
		});
		$("#super_submit").click(function(){
				GUOGUO.superUser();
		});
		//选择画报下拉框
		$("#pictorial_select_button").click(function(){
			$("#pictorial_select_ls").toggle();
		});
		
		//关闭发布微博弹出框
		$("#weibo_dialog_close").click(function(){
			hideDivMiddle("weibo_dialog");
		});
	});
	
	//发表心情 
	function faBiao() {
		var xinQing = $("#textarea_content").val();
		var doingTag = $("#doing_tag_name").val();
		var tagArray = new Array();
		if(!IsNull(doingTag)){
			tagArray = doingTag.split(',');
			if(doingTag=="最多可以添加十个标签,用逗号隔开,每个标签最多十个字符"
				&& $("#doing_tag_name").attr("class")=="doingTag"){
				doingTag="";
			}
		}
		
		//标签不能超过十个
		if(tagArray.length>10){
			alert.text("标签最多可以添加10个");
			return;
		}
		//一个标签不能超过十个字符
		for(var i=0; i<tagArray.length; i++){
			if(tagArray[i].length>10){
				alert("一个标签不能超过10个字符");
				return;
			}
		}
		
		var pictorial = $("#pictorial_id").val();
		if(!IsNull(pictorial)){
			if(doingProductList.size() < 1 && doingImgList.size() < 1){
				alert("画报中至少需要上传一张图片或一件商品才能发表哟");
				return ;
			}
		}
		
		if(xinQing=="#输入话题标题#"){
			alert("再说点什么吧");
			return;
		}
		if(${superMan.identifier=='superMan'}){
			if(IsNull(xinQing)){
				$.post("superEveryHome.htm",  function(data) {
							window.location.href="family?id="+data.msg;
				},"json");
			}else if(xinQing.length > 140){
				alert("最多可以输入140个字，您输入的太多了");
				return ;
			}else{
				saveDoingNew(xinQing,doingTag);
			}
		}else{
			if(IsNull(xinQing)){
				alert("请输入内容");
				return ;
			}else if(xinQing.length > 140){
				alert("最多可以输入140个字，您输入的太多了");
				return ;
			}else{
				saveDoingNew(xinQing,doingTag);
			}
		}
		
	}
	//新版本微博保存
	function saveDoingNew(xinQing,doingTag){
		var picture_url = '';
		var picture_thumbnail = '';
		var picture_url2 = '';
		var picture_thumbnail2 = '';
		var picture_url3 = '';
		var picture_thumbnail3 = '';
		var image_server='';
		var isShare=false;
		var documCk=document.getElementById("cb_share");
		if(documCk!=null){
			isShare=documCk.checked;
		}
		if(doingImgList.size()>0){
			for(var i = 0;i < doingImgList.size();i++){
				var doingImg = doingImgList.get(i);
				switch(i){
					case 0:{
						picture_url = doingImg.original;
						picture_thumbnail = doingImg.thumbnail;
						image_server = doingImg.imageServer;
						break;
					}
					case 1:{
						picture_url2 = doingImg.original;
						picture_thumbnail2 = doingImg.thumbnail;
						break;
					}
					case 2:{
						picture_url3 = doingImg.original;
						picture_thumbnail3 = doingImg.thumbnail;
						break;
					}
				}
			}
		}
		var productList = new Array();
		if(doingProductList.size() > 0){
			for(var i = 0; i < doingProductList.size(); i++){
				productList.push(doingProductList.get(i));
			}
		}
		var pictureList = new Array();
		if(doingImgList.size() > 0){
			for(var i = 0; i < doingImgList.size(); i++){
				pictureList.push(doingImgList.get(i));
			}
		}
		
		
		$("#doing_submit").unbind("click");
		$.post("saveDoingNew.htm", {
				'content' : xinQing ,
				'imageServer':image_server,
				'productList':escape($.toJSON(productList)),
				'videoUrl':	$("#doing_video_url").val(),
				'videoPic':	$("#doing_video_pic").val(),
				'ownerType':'family',
				'tag' : doingTag,
				'pictureList' : escape($.toJSON(pictureList)),
				'pictorial':$("#pictorial_id").val(),
				'isShare':isShare
			}, function(data) {
				if (data.code == '1') {
					if(${superMan.identifier=='superMan'}){
						window.location.href="family?id="+data.msg;
					}
					else{
						window.location.reload();
						}
				}else{
					alert(data.msg);
				}
			},"json");
		
	}
	
	
	
	
	function deleteUploadImg(){
		$.post("deleteDoingImg.htm",{
			'pictureUrl':$("#doing_image_original").val(),
			'pictureThumbnail':$("#doing_image_thumbnail").val(),
			'imageServer':	$("#doing_image_server").val()
		});
		$("#doing_image_thumbnail").val("");
		$("#doing_image_original").val("");
		$("#doing_image_server").val("");
		$("#doing_upload_img_div").show();
		$("#doing_div_preview_parent").hide();
	}
	function setSelectRange( textarea, start, end ){ 
		if ( typeof textarea.createTextRange != 'undefined' )// IE 
		{ 
			var range = textarea.createTextRange(); 
			// 先把相对起点移动到0处 
			range.moveStart( "character", 0) 
			range.moveEnd( "character", 0); 
			range.collapse( true); // 移动插入光标到start处 
			range.moveEnd( "character", end); 
			range.moveStart( "character", start); 
			range.select(); 
		} // if 
		else if ( typeof textarea.setSelectionRange != 'undefined' ) 
		　{ 
		　　 textarea.setSelectionRange(start, end); 
		　　 textarea.focus(); 
		　} // else 
	} 
	
	//点击要提到的好友
	function mentionMine(self){
		$("#textarea_content").insertAtCaret(self.title);
		$("#montion_mine").html("");
	}
	
	function appendDoingTagName(self){
		if($("#doing_tag_name").val()=="最多可以添加十个标签,用逗号隔开,每个标签最多十个字符"
					&& $("#doing_tag_name").attr("class")=="doingTag"){
			$('#doing_tag_name').val("");
			$("#doing_tag_name").attr("class", "inputText");
		}
		var doingTag = $('#doing_tag_name').val();
		if(doingTag==""){
			$('#doing_tag_name').val($(self).html());
		}else{
			$('#doing_tag_name').val(doingTag+","+$(self).html());
		}
	}
	
	
// 新添加的商品信息		
	function doingProudctDialog(){
		$("#lb_pic").remove().hide();	
		if(doingProductList.size() >=3){
			alert("最多只能发布三个商品");
			return ;
		}	
			
		var size = $("#lb_goods").size();	
		if(size < 1){
			$(".blink").append('<div id="lb_goods" class="light_box" style="top: 25px; left: 40px; display: block;position:absolute;z-index:1000000"></div>');
		}
		$("#lb_goods").load("doingProduct.htm").show();
	}
// 添加图片弹出框		
	function doingImgUploadDialog(){
		$("#lb_goods").remove().hide();
		if(doingImgList.size() >=3){
			alert("最多只能发三张图片");
			return ;
		}
		var size = $("#lb_pic").size();	
		if(size < 1){
			$(".blink").append('<div id="lb_pic" class="light_box" style="top: 25px; left: 40px; display: block;position:absolute;z-index:1000000"></div>');
		}
		$("#lb_pic").load("doingImgUploadDialog.htm").show();
	}
//删除商品信息		
	function delDoingProduct(obj){
		$(obj).parent().parent().remove();
		var productNumber = doingProductList.size();
		var delCount = -1;
		for(var i = 0; i < productNumber; i++){
			var picUrl = $(obj).parent().find(".i").attr("src");
			var doingProductI = doingProductList.get(i);
			if(doingProductI.imageServer+doingProductI.picThumb+"_100x100.jpg" == picUrl){
				delCount = i;
				$.post("delPicPro.htm",{
					picUrl:doingProductI.picUrl,
					picUrlThumb:doingProductI.picThumb
				},function(data){
				});
			}
			
		}
		if(delCount != -1){
			doingProductList.remove(delCount);
		}
	}
	//删除上传图片信息
	function delDoingImg(obj){
		$(obj).parent().parent().remove();
		var productNumber = doingImgList.size();
		var delCount = -1;
		for(var i = 0; i < productNumber; i++){
			var picUrl = $(obj).parent().find(".i").attr("src");
			var doingImg = doingImgList.get(i);
			if((doingImg.imageServer+doingImg.thumbnail+"_100x100.jpg") == picUrl){
				delCount = i;
				$.post("delPicPro.htm",{
					picUrl:doingImg.pictureUrl,
					picUrlThumb:doingImg.thumbnail
				},function(data){
				});
			}
		}
		if(delCount != -1){
			doingImgList.remove(delCount);
		}
	}
	
	var doingProductList = new ArrayList();
	var doingImgList = new ArrayList();
	
	function doingPicSel(page){
		$("#pictorial_select_ls").load("doingPicSel.htm?page="+page);
	}
</script>

 <div class="pl_content_publisherTop">
	<div node-type="wrap" class="send_weibo send_weibo_current">
		<c:if test="${weiboDialog=='family'}">
			<i class="arrow">◆</i>
		</c:if>
	
		<div class="top_border">
			<input value="${pictorial.identifier}" type="hidden" id="pictorial_id" autocomplete="off"/>
			<div class="addalbumsel" style="width: 420px;height: 20px;float: left;">
				<div class="tag_select tag_select_open" id="pictorial_select_button">
					<c:choose>
						<c:when test="${pictorial != null}">
							<span><c:out value="${pictorial.title}" /></span>
						</c:when>
						<c:otherwise>
							<span>选择画报</span>
						</c:otherwise>
					</c:choose>
				</div>
				<div class="tag_options" style="width: 310px;display: none;" id="pictorial_select_ls">
                   <%@include file="doingPicSel.jsp" %>
               </div>
			</div>
			<div  id="doing_content_error" node-type="num" class="num" style="display: block;float: left;position: relative;">&nbsp;还能输入 <font size="3">140</font> 字</div>
			<c:if test="${weiboDialog=='popup'}">
			<div style="position: absolute;right: 0;"><a href="javascript:;" id="weibo_dialog_close"><img src="imgs/login-close.png" alt="关闭"></a></div>
			</c:if>
		</div>
		<div class="input">
		<div class="bottom_border"><textarea autocomplete="off" onkeyup="GUOGUO.remain('textarea_content','doing_content_error',140)" onkeydown="GUOGUO.remain('textarea_content','doing_content_error',140)" title="输入框" id="textarea_content"></textarea>
		</div>
		</div>
	</div>
	<!-- 同步微博到其他平台 -->
		  <div class="weibobtn">
			
		 	<span id="ck_shere"></span>
			<c:set value="0" var="i" />
			 <c:forEach items="${member.outAccountList }" var="outAccount">
				 <c:if test="${outAccount.enabled==true && outAccount.accessToken!=null && outAccount.accessToken!=''}">
				 	<c:if test="${outAccount.outAccountType=='01' }">
				 		<c:set var="i"  value="${i+1 }" />
						 <img src="imgs/hmenu_weibos.png" />
					</c:if>
					<c:if test="${outAccount.outAccountType=='03' }">
						<c:set var="i"  value="${i+1 }" />
						 <img src="imgs/ico_qq.gif" />
					</c:if>
				</c:if> 
			</c:forEach>
			<a href="toOauth.htm" target="_blank">同步设置</a>
			<c:if test="${i>0 }">
				<script>
					$("#ck_shere").html('<input id="cb_share"  type="checkbox" checked="checked"/>分享到');
				</script>
			</c:if> 
			<input type="button" id="doing_submit" value="分享" class="sharebtn"/>
			<c:if test="${superMan.identifier=='superMan'}">
			<input type="button" id="super_submit" value="切换帐号" class="sharebtn"/>
			</c:if>
		</div>   
		
	<div node-type="widget" class="blink" style="position: relative;z-index: 2;">
		<%@include file="doingFace.jsp"%>
		<img src="imgs/ico_product.gif" /> <a title="商品" node-type="picBtn" class="img" href="javascript:doingProudctDialog();" tabindex="3">商品</a>
		<img src="imgs/ico_photo.gif" /> <a title="图片" node-type="picBtn" class="img" href="javascript:doingImgUploadDialog();" tabindex="3">图片</a>
		<%--<%@include file="doingVideo.jsp"%>
		
	--%></div>					
</div>
<div class="pub_box">
	<ul class="pub_img clearfix" id="doing_product_list">
	</ul>
</div>

<div style="clear: both;"></div>
